<style>
	.show{display: inherit}
	.hide{display: none}
	.layui-btn{margin-right: 10px !important;}
	.layui-btn-group .layui-btn{margin-left: 10px !important;}
	.layui-table-cell {overflow-x: hidden;overflow: inherit; }
	.layui-table-cell{padding:2px 4px;line-height:20px;text-align:center;}
	th span,.layui-table-cell{white-space:normal;}
	.layui-form-item .layui-inline{margin-right:0px;}
	.createBillTemp{line-height:38px;}
	.createBillTemp select{width:180px;height:30px;}
	.fixed-bar{height:auto !important;}
	.redclass{color:red;font-weight:bold;}
	.check{margin-left:8px;}
	.unit_count{text-decoration: underline;padding: 0px 8px;cursor: pointer;color: #3399FF;}
	 body .demo-class .layui-layer-title{background:#FFFFFF;  border: none;}
	 .add_invo_red{background: #d49c81}
	 .help-diy-css{color:red} .diy-brown{color:#c28736}.diy-brown2{color:red}
    /*调用库存样式*/
	.dress_line_code{margin-top:6px;}
	.dress_line_code textarea{height:100px;padding:6px;width:578px}
	.submit_block{padding-left:230px;}
	.checkin_ret{text-align:center;padding-top:30px;}
	.scan_code_ret{color:red;font-weight:bold;margin-bottom:6px;}
	.defective_reason input{padding:2px 4px;}
	.laytable-cell-1-0-26 a{float:left;margin-left: 8px;}
	.laytable-cell-1-0-26{width:200px!important;}
	.layui-tab-content{display: none}
	.layui-table-tool-temp{display: none}
	/*隐藏搜索*/
	/*.sku_input_search,.package_num_search,.order_type_search,.size_search_input,.factory_serarch_input,.created_search{display: none}*/


</style>
<div class="fixed-bar" style="clear:both;">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',['status' => $status])}"  method="get" id="hisi-table-search">
		<div class="layui-form-item">
			<div class="layui-inline ordernum_input_search">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" id="focusOnOrder" name="client_ordernum"  autocomplete="off" inputName="订单号"   placeholder="输入订单号" class="layui-input">
				</div>
			</div>


			<div class="layui-inline sku_input_search">
				<label class="layui-form-label">sku</label>
				<div class="layui-input-inline">
					<input type="text" name="sku" lay-verify="" placeholder="输入sku" class="layui-input">
				</div>
			</div>
			<div class="layui-inline size_search_input">
				<label class="layui-form-label">尺码</label>
				<div class="layui-input-inline">
					{:Form::select('size_name', '', $sizeList, '', '')}
				</div>
			</div>
			<div class="layui-inline factory_serarch_input">
				<label class="layui-form-label">工厂</label>
				<div class="layui-input-inline">
					{:Form::select('factory_id', '', $factoryKV, '', '')}
				</div>
			</div>
<!--			<div class="layui-inline status_serarch">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline">
					{:Form::select('order_status', '', ['' => '全部', 1=>'待打包'], '', '')}
				</div>
			</div>-->
			<div class="layui-inline created_search">
				<label class="layui-form-label ">日期</label>
				<div class="layui-input-inline">
					<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择创建日期" class="layui-input">
				</div>
			</div>

			<div class="layui-inline order_type_search">
				<label class="layui-form-label">订单类型</label>
				<div class="layui-input-inline">
					{:Form::select('remark', '', ['' => '全部', 1=>'订单', 2=>'尾货'], '', '')}
				</div>
			</div>

			<div class="layui-inline searchSubmit">
				<button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
<!--				<button type="button" class="layui-btn layui-btn-primary hisi-export topsearch">导出</button>-->
			</div>
		</div>
	</form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
	<ul class="layui-tab-title">

		<li id="tab-sku-0" class="layui-this tab-shockin-out "><a onclick="statCli(0)" href="#">入库待处理（<span class="red bold stat-num-1">{:arrayGet($statData,0)}</span>条）</a></li>
		<li id="tab-sku-1" class="tab-shockin-out "><a onclick="statCli(1)" href="#">出库待处理（<span class="red bold stat-num-2">{:arrayGet($statData, 1)}</span>条）</a></li>

		<li><a onclick="statCli(2)" href="#">MES库存差异（<span class="red bold stat-num-3">{:arrayGet($statData, 2)}</span>条）</a></li>
		<li><a onclick="statCli(3)" href="#">已完成（<span class="red bold stat-num-4">{:arrayGet($statData, 3)}</span>条）</a></li>
	</ul>
	<div class="layui-tab-content">
		<table id="dataTable" lay-filter="demoEvent"></table>
	</div>
</div>

<div id="StockCheckOut" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			<div class="scan_code">
				<div>实际可处理数：<span style="color:red;font-size:15px;">{{ d.tail_goods_dff }}</span>, 现库存数：<span style="color:red;font-size:15px;">{{ d.stock_count }}</span>,  sku: <span  style="color:red;font-size:15px;">{{ d.sku }} </span> 尺码： <span  style="color:red;font-size:15px;">{{ d.size_name }} </span></div>
				<div class="dress_line_code">
					请扫描要出库的服装：(注：一行一个服装条码)<br />
					<textarea name="out_dress_line_code" id="out_dress_line_code" class="layui-area out_code_input" lay-verify="" placeholder="扫描要出库的服装条码"></textarea>
					<input type="hidden" name="sku_stock" class="sku_stock" value='{{d.sku_stock}}'>
				</div>
				<div class="scan_code_block">验证提示：<span class="scan_code_ret"></span></div>
				<div class="submit_block">
					<button class="layui-btn" lay-submit lay-filter="stock-out-out" >确认出库</button>
				</div>
			</div>
			<div class="checkin_ret hide">处理结果：<span class="act_ret_str"></span>出库成功；<br /></div>
			<div>
				&nbsp;
			</div>
			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<input type="hidden" name="count" value="{{ d.count }}">
			<input type="hidden" name="sku" value="{{ d.sku }}">
			<input type="hidden" name="is_tail_manage" value="{{ d.is_tail_manage }}">
			<input type="hidden" name="need_put_num" value="{{ d.need_put_num }}">
			<input type="hidden" name="client_ordernum" value="{{ d.client_ordernum }}">
			<input type="hidden" name="tail_goods_dff" value="{{ d.tail_goods_dff }}">
			<input type="hidden" name="size_name" class="size_name_input" value="{{ d.size_name }}" lay-reqText="尺码请选择">
			<input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描要出库的服装条码"  class="layui-input outcheckinNum">
			<div>&nbsp;</div>
		</div>
	</form>
</div>
<div id="stockOutInTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			{{#  for(var i in d.list){ }}
			<div class="layui-inline">
				<label class="layui-form-label">{{ d.list[i].size_name }}</label>
				<div class="layui-input-inline">
					<input type="text" name="number[{{ d.list[i].mid }}]" value="" lay-verify="number|required" placeholder="输入数量" class="layui-input">
				</div>
			</div>
			{{#  } }}

			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<div class="layui-inline fr">
				<button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认</button>
			</div>
		</div>
	</form>
</div>
<div id="StockCheckIn" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			<div>实际可处理数：<span style="color:red;font-size:15px;">{{ d.tail_goods_dff }}</span> </div>
			<div align="center">
				<label class="layui-btn layui-btn-danger show_code_input" size_name="{{ d.size_name }}">{{ d.size_name }}</label>
			</div>

			<div class="scan_code">
				<div class="dress_line_code">
					当前录入的尺码：<span class="size_name_span">{{ d.size_name }}</span>，数量：<span class="checkInNumSpan">0</span>件 (注意：一个条码为一件)<br />
					<textarea name="dress_line_code" id="dress_line_code" focus="true"  class="layui-area code_input" lay-verify="" placeholder="扫服装条码"></textarea>
				</div>
				<!--	<div class="defective_reason hide">次品原因：<input type="text" name="defective_reason" value="" placeholder="输入次品原因(非必填)">
                        <input type="hidden" name="stocktype" class="stocktype_input" value="">
                    </div>-->
				<div class="submit_block">
					<button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认入库</button>
				</div>
			</div>
			<div class="checkin_ret hide">处理结果：尺码：<span class="size_name_span"></span>，数量：<span class="checkInNumSpan">0</span>件，入库成功；<br />
				当前订单该尺码总库存：<span class="total_stock"></span>件<br />
				可选择其它尺码继续录入</div>
			<div>
				&nbsp;
			</div>
			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<input type="hidden" name="tail_goods_dff" value="{{ d.tail_goods_dff }}">
			<input type="hidden" name="count" value="{{ d.count }}">
			<input type="hidden" name="need_put_num" value="{{ d.need_put_num }}">
			<input type="hidden" name="is_tail_manage" value="{{ d.is_tail_manage }}">
			<input type="hidden" name="stocktype" value="{{ d.stocktype }}">
			<input type="hidden" name="size_name" class="size_name_input" value="{{d.size_name }}" lay-reqText="尺码请选择">
			<input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描服装条码"  class="layui-input checkinNum">
			<div>&nbsp;</div>
		</div>
	</form>
</div>

{include file="system@block/layui" /}
<script type="text/html" id="OrdernumTpl_red">
	{{# if(d.is_tail_manage==-1 ||  d.is_tail_manage==-2){ }}
	<span class="copy-item add_invo_red">{{ d.client_ordernum }}</span> <br>
	{{# }else{ }}
	<span class="copy-item">{{ d.client_ordernum }}</span> <br>
	{{# } }}
</script>
<script type="text/html" id="OrdernumTpl">
	<span class="copy-item">{{ d.client_ordernum }}</span> <br>
</script>
<script type="text/html" id="packageOrder_num">
	<span class="copy-item">{{ d.packageOrder_num }}</span> <br>
</script>
<script type="text/html" id="packagenum">
	<span class="copy-item">{{ d.package_num }}</span> <br>
</script>

<script type="text/html" id="sku2Tpl">
	<span class="copy-item" style="word-wrap:break-word">{{ d.sku }}</span>
</script>

<script type="text/html" id="skuimgTpl">
	<span class="lay-pic-container" src="{{ d.ori_pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>
<script type="text/html" id="#pack_status">
	{{ d.status }}
</script>

<script type="text/html" id="factoryTpl">
	<span class="blue">{{d.quantity}}</span>
</script>
<script type="text/html" id="tail_over_time">
	{{# if(d.tail_over_time != 0){ }}
	     {{d.tail_over_time}}
	{{# }else{ }}
	      无
	{{# } }}

</script>

<script type="text/html" id="materialTpl">
	{{# if(d.is_share== 1){ }}
	<a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-orange">共</a>
	{{# } }}
	<span class="copy-item">{{ d.mInfo.name }}</span><br />
	{{d.mInfo.color}}
</script>
<script type="text/html" id="total_num_new">
	{{# if(d.status ==2){ }}
	<span class="unit_count" onclick="openCheckoutWindow('{{ d.sku}}','{{d.status}}')">{{ d.total_num}}</span>
	{{# }else{ }}
	<span class="unit_count" onclick="openCheckoutWindow('{{ d.client_ordernum}}','{{d.status}}')">{{ d.total_num}}</span>
	{{# } }}
</script>

<script type="text/html" id="total_need_num">
	{{ d.total_need_num}}
</script>
<script type="text/html" id="total_need_num_out">
	{{ d.total_need_out_num}}
</script>
<script type="text/html" id="tail_goods_dff_end">
	{{ d.tail_goods_dff_end}}
</script>

<script type="text/html" id="unit">
	{{d.mInfo.unit}}
</script>
<script type="text/html" id="color">
	{{d.mInfo.color}}
</script>
<script type="text/html" id="orderType">
	{{# if(d.remark =="尾货"){ }}
		<span style="color: red">尾货单</span>
	{{# }else{ }}
         普通订单
	{{# } }}
</script>

<script type="text/html" title="操作按钮模板" id="buttonMesTpl">

	{{# if(d.sync_status ==1){ }}
	<a href="#" class="green"  data-sku="{{ d.sku}}" data-size="{{ d.size_name}}" >待6小时后系统更新</a>
	{{# }else{ }}
		{{# if(d.mes_tail_dff >=1){ }}
		<a  class="diy-brown copy-item" lay-event="mesSkuDff" data-copy="{{ d.sku}}" data-sku="{{ d.sku}}" data-size="{{ d.size_name}}" >去MES修改</a>
		{{# }else{ }}
		<a  class="diy-brown2 copy-item" lay-event="mesSkuDff" data-copy="{{ d.sku}}" data-sku="{{ d.sku}}" data-size="{{ d.size_name}}" >去MES增加</a>
		{{# } }}

	{{# } }}

</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">

	{{# if(d.status ==0){ }}
	<a href="#" stocktype="not_defective"  data-id="{{d.order_id}}" data-ordernum="{{ d.client_ordernum}}" data-packagenum="{{ d.package_num}}" data-size="{{ d.size_name}}" data-diff="{{ d.tail_goods_dff}}"  lay-event="tailStockOutIn"   class="tail-stock-outin layui-btn layui-btn-normal layui-btn-sm"  title="库存录入">库存录入</a>
	{{# }else if(d.status ==1){ }}
	<a  class="diy-brown copy-item " lay-event="mesSkuDff" data-copy="{{ d.sku}}" data-sku="{{ d.sku}}" data-size="{{ d.size_name}}" >去MES修改</a>
	<br><br>
	<a href="#" data-orderid="{{ d.order_id }}"  data-dff='{{ d.tail_goods_dff}}'   data-ordernum='{{ d.client_ordernum}}'  data-json='{{ d.otherStockList_json }}' class="tail-stock-out layui-btn layui-btn-normal layui-btn-sm" lay-event="tailStockOut" title="调用库存">调用库存</a>
	{{# } }}
	<a href="#"  data-orderid="{{ d.order_id }}"    data-ordernum='{{ d.client_ordernum}}'  data-status="{{ d.status}}"  data-dff='{{ d.tail_goods_dff}}' data-factoryId='{{ d.factory_id}}'  data-size="{{ d.size_name}}"  title="无需处理"  class="layui-btn not-need-handle layui-btn-danger layui-btn-sm "  lay-event="notNeedHandle">无需处理</a>
</script>
<script type="text/html" id="toolbar">
	<div class="layui-btn-group fr_tail_manage" id="wanchengok">
		<a href="#" onclick="addInvoice(-1)" class="layui-btn layui-btn-sm  layui-icon check">新增入库单</a>&nbsp;&nbsp;
		<a href="#" onclick="addInvoice(-2)" class="layui-btn layui-btn-sm  layui-icon check2">新增出库单</a>&nbsp;&nbsp;
		<a href="#"   class= "layui-icon layui-icon-tips help-diy-css help-show">帮助?</a>
	</div>
</script>

<script type="text/html" id="noneData">
	<div class="mt10 pl20 pb50 red"><i class="layui-icon layui-icon-face-cry" style="font-size: 30px;"></i> 尾货无需处理或手工新增</div>
</script>

<script type="text/html" id="detailTpl">
	<a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" title="明细表" class="hisi-iframe blue" hisi-data="{width: '100%', height: '100%'}">打开</a>
	<!--    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" method="get" id="hisi-table-search">-->
	<a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}&export=1" style="cursor:pointer;border: none" class="blue hisi-export">下载</a>
	<!--    <form>-->
</script>
<script type="text/html" id="stallIdTpl">
	<div class="stall-select">
		{:Form::select('stall_id','', $stallsKV, 'stall-ids-{literal}{{d.id}}{/literal}', 'layui-input stall-ids','lay-search="" lay-filter="stallIds" lay-verify="required" data-id="{literal}{{d.id}}{/literal}"')}
	</div>
</script>
<script type="text/javascript">
	var clientStatus = {:json_encode($clientStatus);};
	var factoryKV= {:json_encode($factoryKV);};
	layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
		var $ = layui.jquery;
		var table = layui.table;
		var laydate = layui.laydate;
		var form = layui.form;
		var laytpl=layui.laytpl;
		var layer = layui.layer;
		var initialize=0,second_initialize=0,first_init=0,changetab=0;
		var showmessage='';

		window.status=0;
		//点击tab
		window.statCli = function(status) {
			var url='{:url("index")}?status='+status;
			window.status=status;

			//只有MES库存差异、完成 点击tab才触发
			if(status==2 || status==3){
				$(".layui-tab-content").show();

			}else{
				//隐藏table
				$(".layui-tab-content").hide();
				//隐藏搜索框
				$('.sku_input_search').hide();
				$('.package_num_search').hide();
				$('.order_type_search').hide();
				$('.size_search_input').hide();
				$('.factory_serarch_input').hide();
				$('.created_search').hide();

			}
			$("#hisi-table-search").attr('action',url);
			$("#seacher").click();

			changetab=1;
			$("#focusOnOrder").focus();
		}


		var opTable=table.render({
			elem: '#dataTable'
			,url: '{:url("", ["status" => $status])}' //数据接口
			,page: true //开启分页
			//,skin: 'row'
			,even: true
			,limit: 30
			,limits: [30,50]
			,text: {
				none : '<div class="mt10 pl20 pb50 red"><i class="layui-icon layui-icon-face-cry" style="font-size: 30px;"></i> 尾货无需处理或手工新增</div>'
			}
			,toolbar: '#toolbar'
			,defaultToolbar: ['exports', 'print']
			,cols: [[ //表头
				,{field: 'Ordernumred', title: '订单号', templet:'#OrdernumTpl_red',width:60}
				,{field: 'col1', title: '订单号', templet:'#OrdernumTpl',width:60}
				,{field: 'sku', title: 'SKU',templet:'#sku2Tpl',width:80}
				,{field: 'skuimg', title: '图片',templet:'#skuimgTpl',width:70}
				,{field: 'size_name', title: '尺码',width:50}
				,{field: 'order_type', title: '订单类型',templet:'#orderType',width:50}
				,{field: 'order_count', title: '订单数',width:40}
				,{field: 'shicai_count', title: '裁床数',width:40}
				,{field: 'jiaohuo_count', title: '车间数',width:40}
				,{field: 'daohuo_count', title: '出货数',width:40}
				,{field: 'order_goods_dff', title: '裁数-订单数',width:60}
				,{field: 'handle_num', title: '可处理数（正30%-裁数）',width:80}
				,{field: 'tail_goods_dff', title: '实际可处理数量',edit:'text',width:80,style:'color:#3399FF;border-bottom:1px dashed #5FB878;'}
				,{field: 'totalnum', title: '工厂库存数',width:50}
				,{field: 'mes_count', title: 'MES库存数',width:50}
				,{field: 'mes_tail_dff', title: 'MES尾货差异（MES数-工厂数）',edit:'text',width:100,style:'color:#3399FF;border-bottom:1px dashed #5FB878;'}
				,{field: 'stock_count', title: '现库存数',width:70}
				,{field: 'stock_outtype', title: '出入库存方式',width:50}
				,{field:'factory_name',title : '工厂',width:120}
				,{field: 'packageOrder_num', title: '订单号/SKU',templet:'#packageOrder_num',width:120}
				,{field:'package_num',title : '大包编号',templet:'#packagenum',width:75}
				,{field: 'client_ordernum', templet:'#OrdernumTpl',title: '订单号',width:60}
				,{field:'total_num',title : '总件数',width:75,templet:"#total_num_new"}
				,{field: 'total_ordernum', title: '总单数',width:60}
				,{field: 'total_need_num', title: '需入库数量',templet:'#total_need_num',width:60}
				,{field: 'total_need_out_num', title: '需要完成',templet:'#total_need_num_out',width:60}
				,{field: 'tail_goods_dff_end', title: '尾货差异数量',templet:'#tail_goods_dff_end',width:60}
				,{field: 'type', title: '操作类型',width:70}
				,{field: 'factory_name_two', title: '工厂',width:120}
				,{field: 'remark', title: '订单类型',width:120}
				,{field: 'tail_over_time', title: '尾完日期', templet: "#tail_over_time",width:130}
				,{field: 'pack_status_stay', title: '状态',width:70}
				,{field:  'buttonTpl',title : '操作',templet:'#buttonTpl',width:200}
		        ,{field: 'create_package_time',templet: function(d){return layui.util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss')}, title: '大包生成日期',width:120}
		        ,{field: 'update_time',templet: function(d){return layui.util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm:ss')}, title: '最新更新时间',width:100}
		        ,{field: 'update_time_sync',templet: function(d){return layui.util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm:ss')}, title: '最新同步时间',width:100}
				,{field: 'reason_content', title: '无需处理原因',width:100}
				,{field: 'd_status', title: '状态',width:70}
				,{field: 'buttonMesTpl',templet:'#buttonMesTpl', title: '操作',width:150}

			]]
			,done: function(res, curr, count){
				var data=res.data;
				var status=res.status;
				 layui.form.render();
				$(".searchSubmit").show();

				if(status==0){
					var need_field=[0,'checkbox','Ordernumred','sku','skuimg','size_name','order_count','shicai_count',
						'jiaohuo_count','daohuo_count','order_goods_dff','handle_num','tail_goods_dff','billing_caigou_count_feed','factory_name','tail_over_time','pack_status_stay','buttonTpl'
						];

					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
					$('table tr th').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					//更新tab切换状态
					$("#tab-sku-0").addClass("layui-this");
					$("#tab-sku-1").attr("class","");

					$('.make-bill').remove();
					$('.layui-form-item .layui-inline').show();
					$('.recheck').hide();
					$('.back').hide();
					$('.checkOutDetailedNew').hide();
					$('.cancelOrders').hide();
					$('.check2').hide();
					$('.layui-table-tool-temp').show();

                    //搜索
					$('.sku_input_search').hide();
					$('.package_num_search').hide();
					$('.order_type_search').hide();
					$('.size_search_input').hide();
					$('.factory_serarch_input').hide();
					$('.created_search').hide();


				}else if(status==1){
					var need_field=[0,'checkbox','Ordernumred','sku','skuimg','size_name','order_type','order_count','shicai_count',
						'jiaohuo_count','daohuo_count','order_goods_dff','handle_num','tail_goods_dff','stock_count','billing_caigou_count_feed','factory_name','tail_over_time','pack_status_stay','buttonTpl'
					];
					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
					$('table tr th').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
                    //更新tab切换状态
					$("#tab-sku-1").addClass("layui-this");
					$("#tab-sku-0").attr("class","");

					$('.make-bill').remove();
					$('.layui-form-item .layui-inline').show();
					$('.recheck').hide();
					$('.back').hide();
					$('.checkOutDetailedNew').hide();
					$('.cancelOrders').hide();
					$('.check').hide();
					$('.layui-table-tool-temp').show();

					//搜索
					$('.sku_input_search').hide();
					$('.package_num_search').hide();
					$('.order_type_search').hide();
					$('.size_search_input').hide();
					$('.factory_serarch_input').hide();
					$('.created_search').hide();

				}else if(status==2){

					var need_field=['sku','skuimg','size_name','totalnum','mes_count',
						'mes_tail_dff','factory_name','update_time_sync','pack_status_stay','buttonMesTpl'
					]
					$('table tr[data-index=0] td').each(function(i){

						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					$('.make-bill').remove();
					$('.check').remove();
					$('.check2').remove();
					$('.help-show').remove();
					$('.back').remove();
					$('.confirmon').hide();

					$('.layui-form-item .layui-inline').show();
					//$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
					//$(".topsearch").hide();
					$('.checkOutDetailedNew').hide();

					//搜索
					$('.order_type_search').hide();

					$('.tail_stock_search').hide();
					$('.size_search_input').hide();
				}else if(status==3){

					var need_field=['checkbox','packageOrder_num','total_num','total_ordernum','total_need_out_num','factory_name_two','type','update_time','d_status']
					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
					$('table tr th').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
					$('.make-bill').remove();
					$('.check').remove();
					$('.check2').remove();
					$('.help-show').remove();
					$('.back').remove();
					$('.cancelOrders').hide();
					$('.checkOutDetailedNew').show();
					$('.confirmon').hide();

					$('.layui-form-item .layui-inline').show();
					// $('.layui-form-item .layui-inline').hide();
					//$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
					$(".hisi-export").show();

					//搜索
					$('.sku_input_search').hide();
					$('.tail_stock_search').hide();
					$('.size_search_input').hide();
					$('.package_num_search').hide();

				}

				if (res.statData != [] ) {
					var total=0,stat=res.statData;
					for(var i in stat) {
						total= total+Number(stat[i]);
					}
					$('.stat-num-1').text(stat[0]?stat[0]:0);
					$('.stat-num-2').text(stat[1]?stat[1]:0);
					$('.stat-num-3').text(stat[2]?stat[2]:0);
					$('.stat-num-4').text(stat[3]?stat[3]:0);
				}

				table.on('edit(demoEvent)', function(obj){
					var value = obj.value //得到修改后的值
							,d = obj.data //得到所在行所有键值
							,field = obj.field; //得到字段
					var id=d.id;
					if (field == 'tail_goods_dff') {
						$.ajax({
							type: "POST",
							url: "{:url('index')}?action=changeSkuDiff",
							data: "id="+d.id+"&tail_goods_dff="+value,
							dataType:"json",
							success: function(res){
								layer.msg('已修改', {icon: 1});
							}
						});
					}

				});

				//重要！ 订单号扫码-》弹出窗口（入库或出库）。并默认赋值一条数据
				if(res.client_ordernum !='' && (status==0 || status==1)) {
					//点击搜索时，显示表格
					$(".layui-tab-content").show();
					var param=[];
					// console.log(data);
					 if(data.length>0){
						 if (status == 1) {
							 param.tail_goods_dff = data[0].tail_goods_dff;
							 param.count = res.count;
							 param.dress_line_code_list = data[0].otherStockList_json;
							 param.order_id_list = data[0].order_id;
							 param.need_put_num =  data[0].tail_goods_dff;
							 param.stock_count =  data[0].stock_count;
							 param.size_name =  data[0].size_name;
							 param.is_tail_manage =  data[0].is_tail_manage;
							 param.sku =  data[0].sku;
							 param.client_ordernum_list = data[0].client_ordernum;
							 stockOut(param);
						 } else if (status == 0) {
							 param.tail_goods_dff = data[0].tail_goods_dff;
							 param.orderId = data[0].order_id;
							 param.title = $(this).text();
							 param.count = res.count;
							 param.stocktype = "not_defective";
							 param.orderNum = data[0].client_ordernum;
							 param.is_tail_manage = data[0].is_tail_manage;
							 param.json =  data[0].otherStockList_json;
							 param.packageNum = data[0].client_ordernum;
							 param.size_name = data[0].size_name;
							 param.need_put_num = data[0].tail_goods_dff;
							 stockOutIn(param);
						 }
					 }


				}
			}
		});
		//点击入库、出库 隐藏其它搜索框
		$(document).on('click','.tab-shockin-out',function(){
			$('.sku_input_search').hide();
			$('.package_num_search').hide();
			$('.order_type_search').hide();
			$('.size_search_input').hide();
			$('.factory_serarch_input').hide();
			$('.created_search').hide();
		});
		form.on('select(stallIds)', function(data){
			var val=data.value,id=data.elem.id;
			var elem=($('#'+id));
			$.ajax({
				type: "POST",
				url: "{:url('stallFeedEdit')}",
				data: "id="+elem.attr("data-id")+"&stall_id="+elem.val(),
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						layer.msg(res.msg, {icon: 1});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
		});


		window.trRemove = function(n) {
			$('table tr td:nth-child('+n+')').remove();
			$('table tr th:nth-child('+n+')').remove();
		}
		//鼠标的光标定位
		$("#focusOnOrder").focus();

		//设置url参数值
		window.setUrlParam=function(tabs) {
			var para_name=[$(tabs).attr('name')];
			var para_value=[$(tabs).val()];

			//para_name, para_value
			var oUrl = $(".confirmSubmitCreateBill").eq(1).attr("data-href").toString();
			for(var i=0;i<para_name.length;i++)
			{
				var re=eval('/('+ para_name[i]+'=)([^&]*)/gi');
				oUrl= oUrl.replace(re,para_name[i]+'='+para_value[i]);
			}
			$(".confirmSubmitCreateBill").eq(1).attr("data-href",oUrl);
		}


		$(document).on('click','.confirmSubmitCreateBill',function(){
			layer.close(layerDefective);
		});

		//详细
		window.openCheckoutWindow = function(id_list,status=0) {

			var title;
			var widthDetail='1200px';
			var heightDetail='600px';
			title='完成清单';
			layerStockOutIn = layer.open({
				type: 2
				,area: [widthDetail,heightDetail]
				,offset: 'auto'
				,shade:[0.1, '#393D49']
				,anim: 5
				,skin:'demo-class'
				,shadeClose:true
				,title:title
				,content: "{:url('index')}?action=detailList&id_list="+id_list+"&status="+status
			});
		}
		//新增入库单
		window.addInvoice =function (status){
			var client_ordernum=$('#focusOnOrder').val();
			var title='新增入库单';
			 if(status==-2) var title='新增出库单';
			layerStockOutIn = layer.open({
				type: 2
				,area: ['500px','400px']
				,offset: 'auto'
				,shade:[0.3, '#393D49']
				,anim: 5
				,skin:'layui-layer-molv'
				,shadeClose:true
				,title:title
				,content: "{:url('addInvoice')}?type="+status+"&client_ordernum="+client_ordernum
			});
		}
		//按钮：库存录入、调用库存、无需处理、去mes修改
		table.on('tool(demoEvent)', function(obj){
			var parm=[];
			if(obj.event === 'tailStockOut') {
				parm.tail_goods_dff = obj.data.tail_goods_dff;
				parm.stock_count = obj.data.stock_count;
				parm.size_name = obj.data.size_name;
				parm.sku = obj.data.sku;
				parm.is_tail_manage = obj.data.is_tail_manage;
				parm.dress_line_code_list = $(this).attr("data-json");
				parm.order_id_list = $(this).attr("data-orderid");
				parm.need_put_num = $(this).attr("data-dff");
				parm.client_ordernum_list = $(this).attr("data-ordernum");
				stockOut(parm);
			}
            else if(obj.event === 'tailStockOutIn') {
				parm.tail_goods_dff = obj.data.tail_goods_dff;
				parm.is_tail_manage = obj.data.is_tail_manage;
				parm.orderId = $(this).attr('data-id');
				parm.title = $(this).text();
				parm.stocktype = $(this).attr("stocktype");
				parm.orderNum = $(this).attr('data-ordernum');
				parm.json = $(this).attr('data-json');
				parm.packageNum = $(this).attr('data-packagenum');
				parm.size_name = $(this).attr('data-size');
				parm.need_put_num = $(this).attr('data-diff');
				stockOutIn(parm);
			}else if(obj.event === 'notNeedHandle') {
				parm.tail_goods_dff = obj.data.tail_goods_dff;
				parm.size_name = $(this).attr('data-size');
				parm.need_put_num = $(this).attr('data-dff');
				parm.status = $(this).attr('data-status');
				parm.orderId = $(this).attr('data-orderid');
				parm.factory_id = $(this).attr('data-factoryId');
				parm.client_ordernum_list = $(this).attr("data-ordernum");
				notNeedHandle(parm);
			}else if(obj.event === 'mesSkuDff') {
				$(this).text('待6小时后系统更新');
				$(this).addClass('green');
				parm.size_name = $(this).attr('data-size');
				parm.sku = $(this).attr("data-sku");
				mesSkuDff(parm);
			}



		});

		window.mesSkuDff = function(parm){
			var myMsg =layer.load(1, {
				shade: [0.1,'#fff'] //0.1透明度的白色背景
			});
			$.ajax({
				type: "POST",
				url: "{:url('applyMesSync')}",
				data: 'sku='+parm.sku+'&size_name='+parm.size_name,
				dataType:"json",
				success: function(res){
					layer.close(myMsg);
					if (res.code == 1) {
						setTimeout(function() {
							window.open("https://www.020mes.com/#/future/factory/order/tail-goods-list");
						}, 1000);//1秒后跳转
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
						return;
					}
				}
			});
		};

		//无需处理
		window.notNeedHandle =function (parm){
			//无需处理
			var title='请选择原因';
			layerStockOutIn = layer.open({
				type: 2
				,area: ['500px','400px']
				,offset: 'auto'
				,shade:[0.3, '#393D49']
				,anim: 5
				,skin:'layui-layer-molv'
				,shadeClose:true
				,title:title
				,content: "{:url('notNeedHandle')}?order_id="+parm.orderId+'&need_put_num='+parm.need_put_num+'&tail_goods_dff='+parm.need_put_num+'&status='+parm.status+'&size_name='+parm.size_name
			});
		};

		<!--调用库存 Start-->
		var sku_stock='';
	    window.stockOut=function (parm){
			sku_stock = parm.dress_line_code_list;
			console.log(sku_stock);
			var d = [];
			d['url'] = "{:url('stockCheckOut')}?order_id=" + parm.order_id_list;
			d['size_name'] = parm.size_name;
			d['sku'] = parm.sku;
			d['need_put_num'] = parm.need_put_num;
			d['stock_count'] = parm.stock_count;
			d['count'] = parm.count;
			d['tail_goods_dff'] = parm.tail_goods_dff;
			d['is_tail_manage'] = parm.is_tail_manage;
			d['order_id'] = parm.order_id_list;
			d['client_ordernum'] = parm.client_ordernum_list;
			d['sku_stock'] = parm.dress_line_code_list;
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".out_code_input").focus();
			var content = laytpl($('#StockCheckOut').html()).render(d);
			layerStockOut = layer.open({
				type: 1
				, area: ['660px', '320px']
				, offset: '100px'
				//,shade:[0.8, '#393D49']
				, anim: 5
				, skin: 'layui-layer-molv'
				, title: '库存调用-你选择占用库存的订单号：' + parm.client_ordernum_list
				, content: content
				, success: function (layerdom, index) {
					$(".out_code_input").eq(1).focus();
				}
			});
		};
		$(document).on('input propertychange',".out_code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var code_str=',';
			console.log(sku_stock);
			code_str=sku_stock;
			if(dress_line_code.length==17){
				dress_line_code=dress_line_code+"\n";
			}
			var codeNumbers=dress_line_code.split("\n");
			var last_input=codeNumbers[codeNumbers.length-1];
			var r, re;
			var re = eval('/'+last_input+'/ig');
			r = dress_line_code.match(re);   //匹配字符
			$(".scan_code_ret").html('');

			for(var i=0;i<codeNumbers.length;i++){
				if(code_str.indexOf(codeNumbers[i])!=-1){
				}else{
					$(".scan_code_ret").eq(1).html("未找到"+codeNumbers[i]+"的库存信息或该条码不属于当前sku");
				}
			}
			if(codeNumbers[codeNumbers.length-1].length>=17){
				//$(".code_input").eq(1).val(dress_line_code+'\n');
			}
			$(".outcheckinNum").val(codeNumbers.length);
			$(".checkInNumSpan").html(codeNumbers.length);
		});

		form.on('submit(stock-out-out)', function (data) {

			var url = data.field.url;
			$.ajax({
				type: "POST",
				url: url,
				data: data.field,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						$('#stockOutInTpl form')[0].reset();
						$(".total_stock").html(res.data.available_count);
						$(".scan_code").hide();
						$(".checkin_ret").show();
						$(".act_ret_str").html(res.data.act_ret_str);
						layer.msg(res.msg, {icon: 1,end:function(){
								//完成跳转到MES系统改库存
							    if(res.data.jump==1){
									//拷贝sku
									layui.tool.copyText(data.field.sku);

									parm=[];
									parm.size_name = data.field.size_name;
									parm.sku =  data.field.sku;
									mesSkuDff(parm);
								}

								if(res.data.tail_goods_dff >=1) {
									opTable.reload();
									layer.close(layerStockOut);
								}else{
									location.reload();
								}
							}});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
			return false;
		});
		$(document).on('mouseover', '.help-diy-css', function(data){
			var that = this;
			tips =layer.tips(' <br/>注意：<br/><span >1. 入库任务：裁床数-（订单数*1.3） > 0  ，要入库。</span><br/>'+
			' <span> 2. 出库任务：裁床数-（订单数*1.3） < 0  ，有库存才出库。</br>&nbsp;&nbsp;有库存的情况下：<br/>' +
					'    &nbsp; &nbsp;①实际出库数 =   如（差异 > 库存）   显示 库存。 <br/>' +
					'    &nbsp; &nbsp;②实际出库数 =   如（差异 < 库存）   显示 差异数;</span><br/>' +
			' <span>3.实际处理数支持修改;  </span><br/>' +
			'  <span>4.不出现的订单支持手工新增。  </span><br/><br/><br/>',
			this,{tips:[2,'#3595CC'],time:0,area: 'auto',maxWidth:720});
		}).on('mouseleave', '.help-diy-css', function(){
			layer.close(tips);
		    });
		<!--调用库存 end-->

		<!--库存录入 start-->
		var layerStockOutIn = null;
		window.stockOutIn=function(parm){
			var d = [];
			d['sku_stock']=parm.json;
			d['order_id'] = parm.orderId;
			d['stocktype'] = parm.stocktype;
			d['client_ordernum'] = parm.orderNum;
			d['package_num'] = parm.packageNum;
			d['size_name'] = parm.size_name;
			d['is_tail_manage'] = parm.is_tail_manage;
			d['count'] = parm.count;
			d['tail_goods_dff'] = parm.tail_goods_dff;
			d['need_put_num'] = parm.need_put_num;
			d['url'] = "{:url('stockCheckIn')}?order_id=" + parm.orderId;
			var content = laytpl($('#StockCheckIn').html()).render(d);
			layerStockOutIn = layer.open({
				type: 1
				,area: ['650px','350px']
				,offset: '100px'
				,shade:[0.3, '#393D49']
				,anim: 5
				,shadeClose:true
				,skin:'layui-layer-molv'
				,title:parm.title+'-当前入库的订单号：'+parm.orderNum
				,content: content
				, success: function (layerdom, index) {
					$("textarea").focus();
				}
			});

		};

		form.on('submit(stock-out-in)', function (data) {
			var url = data.field.url;
			$.ajax({
				type: "POST",
				url: url,
				data: data.field,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						$('#StockCheckIn form')[0].reset();
						//layer.close(layerStockOutIn);
						$(".total_stock").html(res.data.available_count);
						$(".checkInNumSpan").html(res.data.checkin_count);
						$(".scan_code").hide();
						$(".checkin_ret").show();
						$(".checkinNum").eq(0).val('');
						$(".checkinNum").eq(1).val('');
						layer.msg(res.msg, {time: 2000, icon: 1}, function () {

							$(".checkInNumSpan").html(0);
							$(".scan_code").show();
							$(".checkin_ret").hide();

							$(".code_input").eq(1).val('');
							$(".code_input").eq(1).focus();
							layer.close(layerStockOutIn);

							if(res.data.tail_goods_dff >=1){
								opTable.reload();
							}else{
								location.reload();
							}
						});

					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});

			return false;
		});
		$(document).on('click','.show_code_input',function(){
			$(".size_name_span").html($(this).attr('size_name'));
			$(".size_name_input").val($(this).attr('size_name'));
			$(".checkInNumSpan").html(0);
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".code_input").eq(1).val('');
			$(".code_input").eq(1).focus();
		});
		$(document).on('input propertychange',".code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var codes=dress_line_code.replace(/\n/g,"");
			var input_count=0;
			codes=codes.replace(/\r/g,"");
			var codeNumbers=codes.split(";");
			if(codeNumbers[codeNumbers.length-1].length>=17){
				$(".code_input").eq(1).val(codes+';');
				input_count=1;
			}
			$(".checkinNum").val(codeNumbers.length-1+input_count);
			$(".checkInNumSpan").html(codeNumbers.length-1+input_count);

		});
		<!--库存录入 end-->


		// 刷新当前页
		window.reloadTable = function () {
			var that = $("#hisi-table-search"),
					arr = that.serializeArray(),
					where = new Array(),
					dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
					currPage = $(".layui-laypage-em").next().html(),
					options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
			for(var i in arr) {
				where[arr[i].name] = arr[i].value;
			}
			options.url = that.attr('action');
			options.where = where;

			opTable.reload(options);
			return false;
		}

	});
</script>